local std_print = print

function print(...)
	std_print(('[%.3f]'):format(os.clock()), ...)
end
local function _proc(func_table)
	local t = {}
	for i, v in pairs(func_table) do
		table.insert(t, ("%s = %s"):format(i, v))
	end
	return table.concat(t, '\n')
end

function DumpFile()
	local functs = {}
	local jass = require('jass.common')
	local japi = require('jass.japi')
	local jg = require('jass.globals')
	local j1 = require("jass.hook")
	local j2 = require("jass.runtime")
	local j3 = require("jass.slk")
	local j4 = require("jass.console")
	local j5 = require("jass.debug")
	local j6 = require("jass.message")
	local j7 = require("jass.bignum")
	local j8 = require("jass.log")
	local j9 = require("jass.ai")
	local j10 = require("jass.selector")
	table.insert(functs, jass)
	table.insert(functs, japi )
	table.insert(functs, jg )
	table.insert(functs, j1 )
	table.insert(functs, j2 )
	table.insert(functs, j3 )
	table.insert(functs, j4 )
	table.insert(functs, j5 )
	table.insert(functs, j6 )
	table.insert(functs, j7 )
	table.insert(functs, j8 )
	table.insert(functs, j9 )
	table.insert(functs, j10)

	local str = ""
	for i, v in ipairs(functs) do
		str = str .. _proc(v) .. '\n'
	end
	local file = io.open('debuglog.txt', 'a+')
	file:write(str)
	file:close()
end

function DumpHandle()
	print('dump handle')
	local unit = require('types.unit')
	local units = unit.all_units
	local str = _proc(units)
	local file = io.open('debuglog.txt', 'w+')
	file:write(str)
	file:close()
end

local function main()
	print 'hello loli!'
	--print ('package.path = ', package.path)

	require 'GameEnum'
	require 'common.init'
	require 'config'
	require 'maps.mapevent'
	require 'war3.id'
	require 'war3.api'
	require 'util.log'
	require 'ac.init'
	require 'util.error'

	local runtime = require 'jass.runtime'
	if runtime.perftrace then
		runtime.perftrace()
		ac.loop(10000, function()
			log.info('perftrace', runtime.perftrace())
		end)
	end

	ac.lni_loader('unit')

	require 'ModuleMgr.init'

	local rect		= require 'types.rect'
	local circle	= require 'types.circle'
	local region	= require 'types.region'
	local effect	= require 'types.effect'
	local fogmodifier	= require 'types.fogmodifier'
	local move		= require 'types.move'
	local unit		= require 'types.unit'
	local attribute	= require 'types.attribute'
	local hero		= require 'types.hero'
	local damage	= require 'types.damage'
	local heal		= require 'types.heal'
	local mover		= require 'types.mover'
	require 'types.mover.target'
	require 'types.mover.line'

	local follow	= require 'types.follow'
	local texttag	= require 'types.texttag'
	local lightning	= require 'types.lightning'
	local path_block	= require 'types.path_block'
	local item		= require 'types.item'
	local game		= require 'types.game'
	local shop		= require 'types.shop.shop'
	local sound		= require 'types.sound'
	local sync		= require 'types.sync'
	local response	= require 'types.response'
	--local record	= require 'types.record'

	--初始化
	texttag.init()
	shop.init()
	path_block.init()
	game.init()

	--game.register_observer('hero move', move.update)
	--game.register_observer('mover move', mover.move)
	--game.register_observer('path_block', path_block.update)
	--game.register_observer('follow move', follow.move)
	--game.register_observer('lightning', lightning.update)
	--game.register_observer('texttag', texttag.update)
	--game.register_observer('mover hit', mover.hit)

	require 'war3.target_data'
	require 'war3.order_id'

	--测试
	require 'test.init'
	
	--游戏
	local map = require 'maps.map'
    map.init()

    --保存预设单位
    --unit.saveDefaultUnits()


	--加载热补丁
	--require 'types.hot_fix'

	--require 'test.sound'
	local jass = require 'jass.common'
	jass.FogEnable(false)
	local range = 20000
	local rect = rect.create(-range, -range, range, range)
	local fogmod = fogmodifier.create(g_playerMgr(1), rect, true, true, false)
	g_playerMgr.self:setCamera(map.rects['选人区域'], 0)
	--print(jass.IsMapFlagSet(8192 * 2))

end

main()
